package main

import (
	"encoding/json"
	"errors"
	"fmt"
	"strings"
)

// map1test
func map1test() {
	var map1 = map[string][]string{
		"alicent": {"asd", "asdasd"},
		"kso1":    {"111", "asd", "zxc"},
	}
	fmt.Println(map1)
	map2 := map[string]string{}
	map2["charlie"] = "asd"
	delete(map2, "charlie")
	map2["cha2rlie11"] = "asd1"
	map2["char1lie2"] = "asd2"
	map2["cha22rlie3"] = "asd3"
	map2["acharlied"] = "asd"
	for k, v := range map2 {
		if strings.Contains(k, "charlie") {
			fmt.Println(k, "contains charlie", v)
		}
	}
	fmt.Println(map2)
}
func map2test(jsonstring2 string) Persion {
	fmt.Println(jsonstring2)
	per := Persion{}
	err := json.Unmarshal([]byte(jsonstring2), &per)
	if err != nil {
		fmt.Println("Errors: ", err)
	}
	return per
}
func map3test(interfacejson string) error {
	if len(interfacejson) == 0 {
		errors.New("json string is nil!!")
	}
	var f interface{}
	var newbyte = []byte(interfacejson)
	err := json.Unmarshal(newbyte, &f)
	if err != nil {
		return err
	}
	if m, ok := f.(map[string]interface{}); ok {
		fmt.Printf("map[string]interface{})== %v == :  %v", m, fmt.Sprint("fmt sprint :", ok))
	} else {
		return errors.New(fmt.Sprint("fmt sprint :", ok))
	}
	return nil
}

type Persion struct {
	Name string `json:"name"`
	Age  int    `json:"age"`
	City string `json:"city"`
}
